﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using ExtPageBuilder;
using ExtSite.Classes;

namespace ExtSite
{
    public partial class List : BasePage
    {
        ExtListPage _page = new ExtListPage();
        protected void Page_Init(object sender, EventArgs e){
            
        }
        protected void Page_Load(object sender, EventArgs e)
        {

            
            this._page.LanguageID = "1033";
            string obid = Request.QueryString["ob"];
            
            string editable = Request.QueryString["edi"];
            if (editable == "1")
                this._page.Editable = true;
            if (string.IsNullOrEmpty(obid))
                return;
            var db= new DataConfigClassesDataContext();
            Classes.Object ob = db.Objects.SingleOrDefault(o => o.ID == int.Parse(obid));
            if (ob != null)
            {
                ExtPageBuilder.Object oe = new ExtPageBuilder.Object();
                
                ClsFunctions.CopyObject(oe, ob);
                oe.Items = new List<ExtPageBuilder.Object_property>();
                List<Classes.Object_property> ops = db.Object_properties.Where(o => o.Object_id == int.Parse(obid)).ToList<Classes.Object_property>();
                
                foreach (Classes.Object_property p in ops)
                {
                    ExtPageBuilder.Object_property o = new ExtPageBuilder.Object_property();
                    ClsFunctions.CopyObject(o, p);
                    oe.Items.Add(o);
                }
                this._page.PageObject = oe;
                this._page.Grid.Flex = 1;
                this._page.Grid.Layout = "FitLayout";
                this.ViewPortMain.Items.Add(this._page.Grid);
            }
        }
    }
}
